updated YCbCr coefficients
authorØyvind Kolås <ok@src.gnome.org>
Tue, 16 Aug 2005 08:26:27 +0000 (08:26 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Tue, 16 Aug 2005 08:26:27 +0000 (08:26 +0000)
ChangeLog
babl/base/model-ycbcr.c
tests/rgb_to_ycbcr.c
tests/rgb_to_ycbcr_to_rgb.c

index ed4f524bd482ba52c479ddd5f9c3d915c724af4c..c5f9880a0c719451d1cbeb5dc8d7a19de97a8f41 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-08-16  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/base/mode-ycbcr.c: use coefficients from Charles Poyntes color
+       FAQ.
+       * tests/rgb_to_ycbcr_to_rgb.c: changed TOLERANCE to 0.00000000000001
+       * tests/rgb_to_ycbcr.c: changed TOLERANCE as well as reference values.
+
 2005-08-16  Øyvind Kolås  <pippin@gimp.org>
 
        * babl/babl-fish.c: reindentation, no naming of fishes.
index feb0d58f46ef019b37524941d51e1d7d0209bb53..59a8518cd53cbfc026ac2d026adeef0ad5661588 100644 (file)
@@ -94,15 +94,16 @@ rgb_to_ycbcr (int    src_bands,
 
       double luminance, cb, cr;
 
-      luminance =   0.299   * red   +
-                    0.587   * green +
-                    0.114   * blue;
-      cb        = (-0.1687) * red   
-                   -0.3313  * green +
-                    0.5     * blue;
-      cr        =   0.5     * red   
-                   -0.4187  * green +
-                   -0.0813  * blue;
+      /* values taken from Charles Poynton's color FAQ 
+       * http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC28
+       *
+       * this is YPbPr not YCbCr to be exact, it uses the full range, maybe
+       * both should be included with babl under their proper name
+       * 
+       */
+      luminance =  0.299    * red  +0.587    * green  +0.114    * blue;
+      cb        = -0.168736 * red  -0.331264 * green  +0.5      * blue;
+      cr        =  0.5      * red  -0.418688 * green  -0.081312 * blue;
 
       *(double*)dst[0] = luminance;
       *(double*)dst[1] = cb;
@@ -134,10 +135,16 @@ ycbcr_to_rgb (int    src_bands,
 
       double red, green, blue;
 
-      red   = luminance + 1.40200 * cr;
-      green = luminance - 0.34414 * cb - 0.71414 *cr;
-      blue  = luminance + 1.77200 * cb;
-
+      /* values taken from Charles Poynton's color FAQ 
+       * http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC28
+       * 
+       * this is YPbPr not YCbCr to be exact, it uses the full range, maybe
+       * both should be included with babl under their proper name
+       * 
+       */
+      red   = 1.0 * luminance  + 0.0      * cb  + 1.40200    * cr;
+      green = 1.0 * luminance  - 0.344136 * cb  - 0.71414136 * cr;
+      blue  = 1.0 * luminance  + 1.772    * cb  + 0.0        * cr;
 
       *(double*)dst[0] = red;
       *(double*)dst[1] = green;
index 4cbef793ee1fc687eff7498e9bf631af6548d948..a406457da4400346215761b34a98850c15287ed4 100644 (file)
@@ -23,7 +23,7 @@
 #include "babl-internal.h"
 
 #define PIXELS 6
-#define TOLERANCE 0.000001
+#define TOLERANCE 0.00000000000001
 
 float source_buf [PIXELS*3]=
   {0.0, 0.0, 0.0,
@@ -34,12 +34,12 @@ float source_buf [PIXELS*3]=
    0.0, 0.0, 1.0};
 
 float reference_buf [PIXELS*3]=
-  {0.0,   0.0,    0.0,
-   0.5,   0.0,    0.0,
-   1.0,   0.0,    0.0,
-   0.299,-0.1687, 0.5,
-   0.587,-0.3313,-0.4187,
-   0.114, 0.5,   -0.081300};
+  {0.0,    0.0,       0.0,
+   0.5,    0.0,       0.0,
+   1.0,    0.0,       0.0,
+   0.299, -0.168736,  0.5,
+   0.587, -0.331264, -0.418688,
+   0.114,  0.5,      -0.081312};
 
 
 float destination_buf [PIXELS*3];
index d78ecb5455df936c3f21d12e45656c127b8005ef..e9a0d1da51d94aed43a513bbba8de1bd6e562e97 100644 (file)
@@ -23,7 +23,7 @@
 #include "babl-internal.h"
 
 #define PIXELS 6
-#define TOLERANCE 0.00
+#define TOLERANCE 0.00002
 
 float source_buf [PIXELS*3]=
   {0.0, 0.0, 0.0,